﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PixentrationEngine;
using System.IO;

namespace PixentrationEngineTest
{
    class TimingHandler
    {
        PixentrationGame PG;
        StreamWriter sw;
        
        public TimingHandler(PixentrationGame PE, StreamWriter sw)
        {            
            PG = PE;
            PE.tick += new GameTimingEventHandler(TimingEventFired);
            this.sw = sw;
        }

        void TimingEventFired(object sender, TimingEventArgs args)
        {
           
            sw.WriteLine("E4 (timer): " + args.timeLeft);
            sw.Flush();

        }

        ~TimingHandler()
        {
            
        }
    }

    class GameStateHandler
    {
        PixentrationGame PG;
        StreamWriter sw;

        public GameStateHandler(PixentrationGame PE, StreamWriter sw)
        {
            PG = PE;
            PG.stateChanged += new GameStateChangedHandler(GameStateEventFired);
            this.sw = sw;
         }

        void GameStateEventFired(object sender, StateEventArgs args)
        {
           
            sw.WriteLine("E5: (game state): " + args.state);

            if (args.state == PixGameState.EndedWithHighScore)
            {
                PixentrationGame PE = (PixentrationGame)sender;

                sw.WriteLine("E11 (ended with high score): Passed");

                Boolean b = PE.SetHighScoreName("Jim");
                if (b == true)
                    sw.WriteLine("E12 (set new high score): Passed");
                else
                    sw.WriteLine("E11 (ended with high score): FAILED");
                    
            }

            sw.Flush();

        }

    }

    class ScoreHandler
    {
        StreamWriter sw;

        public ScoreHandler(PixentrationGame PE, StreamWriter sw)
        {
            PE.scoreChanged += new ScoreChangedHandler(ScoreEventFired);
            this.sw = sw;
        }

        void ScoreEventFired(object sender, ScoreEventArgs args)
        {
            sw.WriteLine("Score event: " + args.newScore + "  Type: " + args.type);
        }
    }
}
